package com.sgb.kjwl.viewmodel.chat;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.harisucici.jetpackbase.base.HBaseViewModel;
import com.qgb.zcore.mmkvutil.CacheMarker;
import com.qgb.zcore.mmkvutil.MkvUtils;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.chat.NewsMenuEntity;
import com.sgb.kjwl.model.entity.chat.UploadNoticeSortEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NewsNoticeModel extends HBaseViewModel {

    public MutableLiveData<List<NewsMenuEntity>> noticeMenuList = new MutableLiveData<>();

    public NewsNoticeModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 获取通知类型列表
     *
     * @param timelineId 通知会话ID
     * @param type       1:首页请求菜单 2:通知界面请求菜单
     */
    public void getNoticeMenuList(String timelineId, String type) {
        Map map = new HashMap();
        String imAccount = MkvUtils.get().getString(MkvUtils.UserData, CacheMarker.ImAccount, "");
        map.put("userId", imAccount);
        map.put("timelineId", timelineId);
        map.put("type", type);
        APIManager.getInstance().getIMServiceAPI().getNewsMenuList(map).enqueue(new ICallBack<BaseEntity<List<NewsMenuEntity>>>(true, true) {
            @Override
            public void onSuccess(BaseEntity<List<NewsMenuEntity>> data) {
                noticeMenuList.postValue(data.getData());
            }
        });
    }

    /**
     * 上传通知排序列表
     *
     * @param sort 通知排序后的列表
     */
    public void uploadNoticeSortList(String timelineId, List<String> sort) {
        UploadNoticeSortEntity entity = new UploadNoticeSortEntity();
        String imAccount = MkvUtils.get().getString(MkvUtils.UserData, CacheMarker.ImAccount, "");
        entity.setUserId(imAccount);
        entity.setNoticeTypeList(sort);
        entity.setType("jingying");
        APIManager.getInstance().getIMServiceAPI().uploadNoticeSortList(entity).enqueue(new ICallBack<BaseEntity>(true, true) {
            @Override
            public void onSuccess(BaseEntity data) {
                getNoticeMenuList(timelineId, "2");
            }
        });
    }
}
